/** 
 * Copyright (C), 2010-2012, AIYOU Software Co.,Ltd. ALL RIGHTS RESERVED. 
 * File name:CommodityAction.java
 * Version:1.0
 * Date:2011-12-17
 * Description: 
 * author:TT_LOVE
 */
package com.tietiao.action.tag;

import java.io.IOException;
import java.util.List;

import javax.annotation.Resource;

import net.sf.json.JSONObject;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.tietiao.common.action.BaseAction;
import com.tietiao.common.util.StringUtil;
import com.tietiao.dao.model.CommodityInfo;
import com.tietiao.dao.model.SysUser;
import com.tietiao.service.commodity.CommodityService;
import com.tietiao.service.label.UserLableService;

@Controller
@Scope("prototype")
@SuppressWarnings("serial")
public class TagAction extends BaseAction {
	@Resource
	private CommodityService commodityService;
	@Resource
	private UserLableService userLableService;
	// 商品列表信息
	private List<CommodityInfo> commodityInfoList;
	// 排序
	private String orderType = "TIETIAO_NUM DESC";
	// 商品信息
	private CommodityInfo commodityInfo;
	// 用户信息
	private SysUser userInfo;
	// 标签名
	private String lableName;
	
	/**
	 * 
	 * @author: TT_LOVE
	 * @Date: 2012-1-3
	 * 
	 * @return
	 */
	public String tagInfo() {
		lableName = request.getParameter("lableName");
		lableName = StringUtil.ISO88591_TO_UTF8(lableName);
		request.setAttribute("attenedLable", userLableService.isAttendLable(getUser().getUserId(), lableName));
		return DEFAULT;
	}
	/**
	 * 
	 * 功能：判断用户是否已经对该标签贴条
	 * @author: zhijian.zhang
	 * @Date: 2012-2-15
	 *
	 * @return
	 */
	public String checkisAdd() throws Exception{
		response.getWriter().append(String.valueOf(userLableService.isAttendLable(getUser().getUserId(), lableName)));
		return null;
	}
	/**
	 * 
	 * 功能：关注或者取消关注标签
	 * @author: whh 
	 */
	public void addOrCanel() throws IOException{
		response.setContentType("text/html");
		JSONObject obj = new JSONObject();
		obj.put("result", true);
		lableName = request.getParameter("lableName");
		if("cancel".equals(request.getParameter("type"))){
			userLableService.dontAttendUserLable(getUser().getUserId(), lableName);
		}else{
			userLableService.attendUserLables(getUser().getUserId(), lableName);
		}
		
		response.getWriter().append(obj.toString());
		response.getWriter().flush();
		response.getWriter().close();
	}
	
	/**
	 * @return the commodityService
	 */
	public CommodityService getCommodityService() {
		return commodityService;
	}

	/**
	 * @param commodityService
	 *            the commodityService to set
	 */
	public void setCommodityService(CommodityService commodityService) {
		this.commodityService = commodityService;
	}

	/**
	 * @return the commodityInfoList
	 */
	public List<CommodityInfo> getCommodityInfoList() {
		return commodityInfoList;
	}

	/**
	 * @param commodityInfoList
	 *            the commodityInfoList to set
	 */
	public void setCommodityInfoList(List<CommodityInfo> commodityInfoList) {
		this.commodityInfoList = commodityInfoList;
	}

	/**
	 * @return the orderType
	 */
	public String getOrderType() {
		return orderType;
	}

	/**
	 * @param orderType
	 *            the orderType to set
	 */
	public void setOrderType(String orderType) {
		this.orderType = orderType;
	}

	/**
	 * @return the rootPicPath
	 */
	public String getRootPicPath() {
		return rootPicPath;
	}

	/**
	 * @param rootPicPath
	 *            the rootPicPath to set
	 */
	public void setRootPicPath(String rootPicPath) {
		this.rootPicPath = rootPicPath;
	}

	/**
	 * @return the commodityInfo
	 */
	public CommodityInfo getCommodityInfo() {
		return commodityInfo;
	}

	/**
	 * @param commodityInfo
	 *            the commodityInfo to set
	 */
	public void setCommodityInfo(CommodityInfo commodityInfo) {
		this.commodityInfo = commodityInfo;
	}

	/**
	 * @return the userInfo
	 */
	public SysUser getUserInfo() {
		return userInfo;
	}

	/**
	 * @param userInfo
	 *            the userInfo to set
	 */
	public void setUserInfo(SysUser userInfo) {
		this.userInfo = userInfo;
	}



	/**
	 * @return the lableName
	 */
	public String getLableName() {
		return lableName;
	}



	/**
	 * @param lableName the lableName to set
	 */
	public void setLableName(String lableName) {
		this.lableName = lableName;
	}
}
